package windowFactoryPackage;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.ArrayList;

public class ReviewWindow extends WindowGenerator{
	//Declare window components
	static ArrayList<JPanel> reviewsPanelList = new ArrayList<JPanel>();
	static ArrayList<JPanel> reviewsButtonPanelList = new ArrayList<JPanel>();
	static ArrayList<ViewUserButton> userButtonList = new ArrayList<ViewUserButton>();
	static ArrayList<JTextArea> reviewsList = new ArrayList<JTextArea>();
	static ArrayList<JLabel> userLabelList = new ArrayList<JLabel>();
	static ArrayList<JLabel> userIDList = new ArrayList<JLabel>();
	static JLabel programLabel = new JLabel("__Program Name__");
	static JLabel ratingLabel = new JLabel("__Rating__ / 5");
	private JPanel mainPanel, northPanel;
	private JScrollPane reviewPane;
	
	public ReviewWindow(){
		//Create Font for JLabels in northPanel
		Font f = new Font("Serif", Font.BOLD, 24);
		this.addWindowFocusListener(new WindowFocusListener(){
			@Override
			public void windowGainedFocus(WindowEvent e) {}
			@Override
			public void windowLostFocus(WindowEvent e) {
				dispose();				
			}			
		});
		
		//Set layout for parent JFrame
		setLayout(new BorderLayout());
		
		//Instantiate northPanel
		northPanel = new JPanel();
		northPanel.setLayout(new BorderLayout());
		
		//Instantiate components for northPanel, add components to panel, add panel to parent JFrame
		
		programLabel.setFont(f);
		
		ratingLabel.setFont(f);
		northPanel.add(programLabel, BorderLayout.CENTER);
		northPanel.add(ratingLabel, BorderLayout.EAST);
		
		add(northPanel, BorderLayout.NORTH);
		
		//Instantiate mainPanel
		mainPanel = new JPanel();
		
		//Instantiate arrays that will hold review information, view user button, add to JScrollPane
		
		for(int i = 0; i<reviewsList.size(); i++){
			reviewsPanelList.add(new JPanel(new BorderLayout()));
			reviewsPanelList.get(i).setBorder(BorderFactory.createEtchedBorder());
			reviewsList.get(i).setEditable(false);
			reviewsList.get(i).setLineWrap(true);
			reviewsList.get(i).setWrapStyleWord(true);
			reviewsPanelList.get(i).add(reviewsList.get(i), BorderLayout.CENTER);
			
			reviewsButtonPanelList.add(new JPanel());
			reviewsButtonPanelList.get(i).setBorder(BorderFactory.createEtchedBorder());
			userLabelList.add(new JLabel("Written By: "));
			reviewsButtonPanelList.get(i).add(userLabelList.get(i));
			reviewsButtonPanelList.get(i).add(userIDList.get(i));
			userButtonList.add(new ViewUserButton());
			reviewsButtonPanelList.get(i).add(userButtonList.get(i));
			reviewsPanelList.get(i).add(reviewsButtonPanelList.get(i), BorderLayout.SOUTH);
		}
		
		mainPanel.setLayout(new GridLayout(reviewsList.size(), 1, 10, 10));
		
		for(int i = 0; i<reviewsList.size(); i++){
			mainPanel.add(reviewsPanelList.get(i));
		}
		
		//Instantiate JScrollPane to hold generated mainPanel
		reviewPane = new JScrollPane(mainPanel);
		reviewPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		reviewPane.getVerticalScrollBar().setUnitIncrement(16);
		
		//Add reviewPane to parent JFrame
		add(reviewPane, BorderLayout.CENTER);		
	}
}
